package com.thon.entity.project;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thon.commons.config.Global;
import com.thon.entity.util.IdEntity;


/**
 * @file ProjectBudget.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年11月8日 下午7:58:40
 * @description: 项目预算实体
 */
@Entity
@Table(name="project_budgets")
public class ProjectBudget extends IdEntity{

	private static final long serialVersionUID = 6414827507246444746L;
	private Integer stage;
	private Date startDate;
	private Date endDate;
	private Integer laborCosts;
	private Integer programCosts;
	private Integer adminCosts;
	private Integer otherCosts;
	private String remark;
	private Project project;
	private String feedback;
	
	public ProjectBudget() {
	}
	public Integer getStage() {
		return stage;
	}
	public void setStage(Integer stage) {
		this.stage = stage;
	}
	
	@DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",timezone="GTM+08:00")
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	
	@DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",timezone="GTM+08:00")
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	public Integer getLaborCosts() {
		return laborCosts;
	}
	public void setLaborCosts(Integer laborCosts) {
		this.laborCosts = laborCosts;
	}
	
	public Integer getProgramCosts() {
		return programCosts;
	}
	public void setProgramCosts(Integer programCosts) {
		this.programCosts = programCosts;
	}
	
	public Integer getAdminCosts() {
		return adminCosts;
	}
	public void setAdminCosts(Integer adminCosts) {
		this.adminCosts = adminCosts;
	}
	
	public Integer getOtherCosts() {
		return otherCosts;
	}
	public void setOtherCosts(Integer otherCosts) {
		this.otherCosts = otherCosts;
	}
	
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="project_id",nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public Project getProject() {
		return project;
	}
	
	@JsonProperty
	public void setProject(Project project) {
		
		this.project = project;
	}
	public String getFeedback() {
		if(!StringUtils.isBlank(feedback)){
			feedback = StringEscapeUtils.unescapeHtml4(feedback);
			feedback = feedback.replaceAll("src=\"../common/attachment/download/", "src=\""+Global.getConfig("img.url"));
		}
		return feedback;
	}
	public void setFeedback(String feedback) {
		this.feedback = feedback;
	}

}
